<script>
	import { LoginByWechat } from '@/api/index';
	import { infoDataCache } from "@/utils/index"
	const listUrl = ['pages/pages/index', 'pages/pages/delivery-order', 'pages/pages/meal-ticket', 'pages/pages/person']
	export default {
		onLaunch: function() {
			// uni.hideTabBar({
			// 	animation: false, // 是否需要动画效果，默认为true 
			// 	success() { },
			// 	fail() { }
			// });
		},
		methods: {
			// 用户隐私协议
			getPrivacySetting() {
				return new Promise(function(resolve, reject) {
					uni.getPrivacySetting({
						success: res => {
							// console.log(
							// 	res) // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
							// console.log('resresresresres', res)
							if (res.needAuthorization) {
								uni.setStorageSync('privacyContractName', res.privacyContractName)
								// uni.setStorageSync('needAuthorization', res.needAuthorization)
								// 	// 需要弹出隐私协议
								// 	// this.setData({
								// 	// 	showPrivacy: true
								// 	// })
							} else {

								// 	// 用户已经同意过隐私协议，所以不需要再弹出隐私协议，也能调用隐私接口
							}
						},
						fail: (e) => {
							console.log(e)
						},
						complete: () => {}
					})
				})
			},
			// 获取code
			bindLogin() {
				return new Promise(function(resolve, reject) {
					uni.login({
						success: function(loginRes) {
							console.log('loginRes', loginRes);
							// return
							if (loginRes.errMsg == 'login:ok') resolve(loginRes.code)
							else {
								uni.showToast({
									title: loginRes.errMsg,
									icon: 'none',
								})
							}
						},
						complete(res) {
							console.log('completebindLogin', res)
						}
					});
				})
				// return promise;
			},
			// 升级版本
			getUpdateManager() {
				const updateManager = uni.getUpdateManager() // 小程序版本更新管理器
				updateManager.onCheckForUpdate(res => { // 检测新版本后的回调
					if (res.hasUpdate) { // 如果有新版本提醒并进行强制升级
						uni.showModal({
							content: '新版本已经准备好，是否重启应用？',
							showCancel: false,
							confirmText: '立即更新',
							success: res => {
								if (res.confirm) {
									updateManager.onUpdateReady(res => { // 新版本下载完成的回调
										updateManager.applyUpdate() // 强制当前小程序应用上新版本并重启
									})
									updateManager.onUpdateFailed(res => { // 新版本下载失败的回调
										// 新版本下载失败，提示用户删除后通过冷启动重新打开
										uni.showModal({
											content: '下载失败，请删除当前小程序后重新打开',
											showCancel: false,
											confirmText: '知道了'
										})
									})
								}
							}
						})
					}
				})
			},
			// 小程序端默认登录
			defaultLogin() {
				const _this = this
				return new Promise(function(resolve, reject) {
					_this.bindLogin().then(code => {
						LoginByWechat({ code: code, appClent: 'lhfp-app' }).then((res) => {
							const { code, data } = res
							if (code === "200") {
								uni.setStorageSync('token', data.token);
								uni.setStorageSync('userInfo', data);
								_this.$isResolve()
							}
							resolve(res);
						});
					})
					// 	resolve(data);
				})
				// return promise;
			},
		},
		onShow: function() {
			// uni.setStorageSync('token','SlcGMIns4K3iy9B6LRRQbKoEya80JTKVdUCEKa8qEuKLg.26b74fdc385e45748cd577f7277938ea')
			// console.log('App Show');
			// let env = uni.getAccountInfoSync().miniProgram.envVersion;
			// uni.setStorageSync('envVersion', env)
			this.getUpdateManager() // 升级版本
			this.getPrivacySetting() // 用户协议
			// this.bindLogin()
			if (!uni.getStorageSync('token')) this.defaultLogin();
			// this.$isResolve()
			else this.$isResolve()
		},
		onHide: function() {
			console.log('App Hide');
		}
	};
</script>

<style lang="scss">
	@import 'uview-ui/index.scss';
	@import './common/index.css';

	/*每个页面公共css */
	page {
		background: #f6f6f6;
	}

	::v-deep.tabs-view .u-tabs__wrapper__nav__item {
		padding: 0 10rpx !important;
		box-sizing: border-box;
	}

	::v-deep.tabs-view-a {
		.u-tabs__wrapper__nav__item {
			padding: 0px 35rpx !important;
			box-sizing: border-box;
		}

		.u-tabs__wrapper__nav__line {
			background: linear-gradient(90deg, #EB0000 0%, #f46a08 100%) !important;
			border-radius: 10rpx !important;
			bottom: 10rpx !important;
		}
	}

	// 我的饭票tap
	::v-deep.sticky-tap {
		.u-tabs__wrapper__nav__item {
			width: 25%;
			padding: 0 !important;
			box-sizing: border-box;
		}

		.u-tabs__wrapper__nav__line {
			background: linear-gradient(90deg, #EB0000 0%, #f46a08 100%) !important;
			border-radius: 10rpx !important;
			bottom: 10rpx !important;
		}
	}

	// 我的优惠券tab
	::v-deep.coupon-tab {
		.u-tabs__wrapper__nav__item {
			width: 33.33%;
		}
	}

	// 零钱包tab
	::v-deep.change-purse__tabs {
		.u-tabs__wrapper__nav__item {
			width: 33.33%;
			padding: 0 !important;
		}

		.u-tabs__wrapper__nav__line {
			display: none;
		}
	}


	// 表单输入框错误提示样式
	::v-deep.u-form-item__body__right__message {
		padding-bottom: 10rpx !important;
	}

	// 导航样式
	::v-deep.delivery-order {
		.u-tabs__wrapper__nav__line {
			bottom: 0rpx !important;
		}
	}

	// 评价列表的样式
	::v-deep.evaluation-tab {
		.u-tabs__wrapper__nav__item {
			width: 20%;
			padding: 0 !important;
		}

		.u-tabs__wrapper__nav__line {
			width: 50rpx !important;
			height: 7rpx !important;
			border-radius: 50rpx !important;
			background: #EB0000 !important;
			bottom: 30rpx !important;
		}
	}

	// 键盘按钮样式
	::v-deep.keyboard {
		.u-button {
			height: 100% !important;
			border-radius: 12rpx !important;
			color: #000000 !important;
			display: flex;
			justify-content: center;
			align-items: center;
			font-size: 1.5rem !important;
			font-weight: 600 !important;
			box-shadow: 0 8rpx 16rpx 0 rgba(0, 0, 0, 0.05) !important;
		}

		.u-button--active {
			// background: RGBA(245, 245, 245, .01)!important;
		}
	}

	// 骨架
	::v-deep.u-skeleton__wrapper__content__rows,
	::v-deep.u-skeleton__wrapper__avatar {
		border-radius: 14rpx !important;
	}

	// 提现输入框
	::v-deep.withdraw {

		.u-input__content,
		.u-input__content__field-wrapper,
		.u-input__content__field-wrapper__field {
			height: 100% !important;
		}

		.u-input__content__field-wrapper__field {
			font-size: 1.875rem !important;
			font-weight: 600 !important;
			color: #000 !important;
		}

		.input-placeholder {
			font-weight: 400 !important;
		}
	}
</style>